﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using Wicresoft.Common;
using JDEduTrain.Framework.Entity;
using JDEduTrain.Framework.Business;

public partial class Page_LectorInfoDetail : BaseAuthenticationPage
{
    public Guid LectorID
    {
        get
        {
            if (Request["LectorID"] != null)
                return new Guid(Request["LectorID"]);
            return Guid.Empty;
        }
    }


    protected void Page_Load(object sender, EventArgs e)
    {
        this.UseTabber = true;
        if (!IsPostBack)
        {
            LectorInfo lector = new LectorInfo(LectorID);
            if (lector.Load())
            {
                tbBirthday.Text = lector.Birthday.ToShortDateString();
                tbFullName.Text = lector.FullName;
                rblSex.SelectedValue = lector.Gender;
                tbBackNvarchar1.Text = lector.BackNvarchar1;
                tbBackNvarchar2.Text = lector.BackNvarchar2;
                tbBackNvarchar3.Text = lector.BackNvarchar3;
                ltBriefInfo.Text = lector.BriefInfo;
                ltDepartmentName.Text = lector.DepartmentName;
                ltJobPosition.Text = lector.JobPosition;

            }
                rblSex.Enabled = false;
                BindExperience();
        }
    }

    protected void BindExperience()
    {
        DataTable dtExperience = BLTrain.GetExperienceByLectorID(LectorID);
        dtExperience.Columns.Add("ShortContent");
        int titleNum = 30;
        foreach (DataRow dr in dtExperience.Rows)
        {
            if (dr["MainContent"].ToString().Length > titleNum)
            {
                dr["ShortContent"] = dr["MainContent"].ToString().Substring(0, titleNum) + "...";
            }
            else
            {
                dr["ShortContent"] = dr["MainContent"];
            }
        }
        rptOrderInfo.DataSource = dtExperience;
        rptOrderInfo.DataBind();
        
    }
    protected void btnRefresh_Click(object sender, EventArgs e)
    {
        BindExperience();
    }

    protected void rptOrderInfo_ItemCommand(object sender, RepeaterCommandEventArgs e)
    {
        ImageButton ibtnEdit = e.Item.FindControl("ibtnEdit") as ImageButton;
        ImageButton ibtnDelete = e.Item.FindControl("ibtnDelete") as ImageButton;
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            if (e.CommandName == "Delete")
            {
                Guid id = new Guid(ibtnDelete.CommandArgument);
                LectorExperience experience = new LectorExperience(id, LectorID);
                if (experience.Exist())
                {
                    experience.Delete();
                    BindExperience();
                }
            }
            else
                if (e.CommandName == "Edit")
                {
                    Guid exID = new Guid(ibtnEdit.CommandArgument);
                    Random ran = new Random();
                    string script = string.Format("<script>editExperience('{0}');</script>", exID);
                    ClientScript.RegisterStartupScript(this.GetType(), "Close", script);
                }
        }
    }

}
